#ifndef HDCAMERA_H
#define HDCAMERA_H

#include <boost/thread/thread.hpp>
#include <DeckLinkAPI.h>

static BMDTimecodeFormat		g_timecodeFormat;

class HDCamera
{
    class HDDelegate : public IDeckLinkInputCallback
    {
    public:
        HDDelegate(char *filename, HDCamera *hdc);
        ~HDDelegate();

        virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
        virtual ULONG STDMETHODCALLTYPE AddRef(void);
        virtual ULONG STDMETHODCALLTYPE  Release(void);
        virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
        virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);

    private:
        ULONG				m_refCount;
        pthread_mutex_t		m_mutex;
        char m_videoFilePrefix[1024];
        char videoOutputFile[1024];
        unsigned long frameCount;
        int g_maxFrames;
        HDCamera *m_HDC;
    };
public:
    HDCamera(IDeckLink *dl, std::string filename);


    void run();

    void capturefinished();
private:
    void localRun();

    IDeckLink *m_deckLink;
    HDDelegate *m_delegate;
    IDeckLinkInput *m_deckLinkInput;
    BMDDisplayMode selectedDisplayMode;
    BMDPixelFormat pixelFormat;
    BMDVideoInputFlags inputFlags;

    pthread_mutex_t	sleepMutex;
    pthread_cond_t	sleepCond;


    char videoFilePrefix[1024];


};

#endif // HDCAMERA_H
